<template>
	<view>
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view slot="top">
				<u-navbar :title="$t('my.discounts.navBartext')" :autoBack="true" :fixed="false"></u-navbar>
			</view>
			<view class="content">
				<view v-for="(item,index) in dataList" :key="index" class="item">
					<u--image :src="item.avatar" radius="10" width="194rpx" height="194rpx"></u--image>
					<view>
						<view class="item_top">
							<view>
								<u--text :text="item.shopname" bold size="16" color="#000" lines="1" margin="0 0 10px 0"></u--text>
								<u--text :text="'有效期至：'+item.validityTime" size="12" color="#989898" lines="1"></u--text>
							</view>
							<view>
								<u--text align="center" :text="item.price" bold size="25" color="#F76853" lines="1"></u--text>
								<u--text align="center" :text="item.name" size="13" color="#F76853" lines="1"></u--text>
							</view>
						</view>
						<view class="btn m-top-10">
							<u-icon @click="openRule(index)" :name="item.show?'arrow-up':'arrow-down'" labelPos="left"
								:label="$t('my.discounts.iconText')" labelColor="#989898" labelSize="12px"></u-icon>
							<u-button :text="$t('my.discounts.btnText')" shape="circle" @click="goDetail(item)"
								:customStyle="btnStyle"></u-button>
						</view>
						<u--text v-if="item.show" :text="item.remark||'暂无内容'" color="#989898" size="13" margin="10px 0 0 0 "></u--text>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				btnStyle: {
					background: "linear-gradient(53deg, #F86D57 0%, #EF3B2C 100%)",
					color: "#fff",
					border: "none",
					width: "auto",
					height: "54rpx",
					margin: "0"
				}
			};
		},
		methods: {
			queryList(pageNo, pageSize) {
				this.$http.post('wanlshop/coupon/getMyList', {
					page: pageNo,
					limit: pageSize,
					state: 1
				}).then(res => {
					if (res.code == 1) {
						res.data.data = res.data.data.map(item => ({
							...item,
							show: false
						}))
						this.$refs.paging.complete(res.data.data)
					} else {
						this.$refs.paging.complete(false)
					}
				})
			},
			openRule(index) {
				this.dataList[index].show = !this.dataList[index].show
			},
			goDetail(item) {
				uni.$u.route({
					url: 'pagesA/home/merchantDetail',
					params: {
						id: item.shop_id
					}
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f7f9;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 20rpx 0;
	}

	.item {
		background-image: url();
		background-repeat: no-repeat;
		background-size: 100% 100%;
		padding: 40rpx;
		display: grid;
		grid-template-columns: 194rpx auto;
		grid-column-gap: 20rpx;

		.item_top {
			display: grid;
			grid-template-columns: 1.5fr 0.8fr;
			grid-column-gap: 20rpx;
			padding-bottom: 25rpx;
			border-bottom: 2rpx dashed #EEEEEE;
		}

		.btn {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
</style>
